<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ReactRedux</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="../../libs/babel.min.js"></script>
    <script src="../../libs/react.development.js"></script>
    <script src="../../libs/react-dom.development.js"></script>
    <script src="../../source/dist/redux.js"></script>
    <script src="../../ReactRedux/lib/index.js"></script>
    <script type="text/babel">
      const reducer = (state, action) => {
        switch (action.type) {
          case "Add":
            return state + 1
            break
          default:
            return 0
            break
        }
      }
      const store = Redux.createStore(reducer)

      store.subscribe(() => {
        console.log("subscribe", store.getState())
      })

      // 执行的结果

      const Child = ReactRedux.connect(
        state => {
          console.log(state) // 1
          return {
            number: state,
          }
        },
        dispatch => ({
          dispatch,
        })
      )(function ChildComponent(props) {
        const add = () => {
          props.dispatch({
            type: "Add",
          })
        }

        return (
          <>
            <div>number = {props?.number} </div>
            <div>
              <button onClick={add}> 加一</button>
            </div>
          </>
        )
      })

      const App = () => {
        return (
          <ReactRedux.Provider store={store}>
            <Child number={100} name={"张三"}></Child>
          </ReactRedux.Provider>
        )
      }

      ReactDOM.render(<App />, document.getElementById("root"))
    </script>
  </body>
</html>
